from pyecharts.charts import Bar,Timeline
from pyecharts.options import LabelOpts
from pyecharts.globals import ThemeType
# 绘制时间线柱状图

country = ["中国", "美国", "英国"]
data1 = [28000, 90000, 70000]
data2 = [30000, 80000, 50000]
data3 = [50000, 60000, 40000]
#创建柱状图
Bar_Chart1 = (
    Bar()
    .add_xaxis(country)
    .add_yaxis("GDP",data1,label_opts= LabelOpts(position="right"))#数值标签在右侧显示
    .reversal_axis()#反转x轴和y轴
             )
Bar_Chart2 = (
    Bar()
    .add_xaxis(country)
    .add_yaxis("GDP",data2,label_opts= LabelOpts(position="right"))#数值标签在右侧显示
    .reversal_axis()#反转x轴和y轴
             )
Bar_Chart3 = (
    Bar()
    .add_xaxis(country)
    .add_yaxis("GDP",data3,label_opts= LabelOpts(position="right"))#数值标签在右侧显示
    .reversal_axis()#反转x轴和y轴
             )
timeline = Timeline({"theme":ThemeType.LIGHT})
timeline.add(Bar_Chart1, "点1")
timeline.add(Bar_Chart2, "点2")
timeline.add(Bar_Chart3, "点3")
#自动播放设置
timeline.add_schema(
    play_interval=1000,#时间间隔1000毫秒
    is_timeline_show=True,#自动播放时显示时间线
    is_auto_play=True,#是否自动播放
    is_loop_play=True#是否循环自动播放
)
timeline.render("时间线柱状图.html")